<script>
$(document).ready(function(){
    $('#total').change(function(){
        if(this.checked){
            
            $('.item').attr('checked',true);
        }else{
             $('.item').attr('checked',false);
        }
        
    });
    
   
})

</script>

<?php if (isset($campos)): ?>
    <table border="1">
        <thead>
            <tr>
                <th><?php echo $this->Form->input('', array(
                        'type' => 'checkbox',
                        'id'=>'total'
                    ));?></th>
                <th>Campo</th>
                <?php if ($tipo != "index"): ?>
                    <th>Tipo de input</th>
                    <th>Etiqueta</th>
                    <th>Tipo de dato</th>
                    <th>Obligatorio</th>
                <?php else: ?>
                    <th></th>
                <?php endif; ?>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($campos as $campo):  ?>
                <tr>

                    <td><?php echo $this->Form->checkbox("", array('hiddenField' => false, 'class'=>'item', 'value' => $campo["COLUMNS"]["Field"], 'name' => "Campos[$objeto][" . $campo["COLUMNS"]["Field"] . "][check]")); ?></td>
                    <td><?php echo $campo["COLUMNS"]["Field"]; ?></td>
                    <?php if ($tipo != "index"): ?>
                        <td><?php echo $this->Form->input("", array( 'options' => array('input' => 'Input', 'hidden' => 'Hidden', 'Checkbox' => 'Checkbox'), 'name' => "Campos[$objeto][" . $campo["COLUMNS"]["Field"] . "][tipo]")); ?></td>
                        <td><?php echo $this->Form->input("", array('value'=>$campo["COLUMNS"]["Field"],'label' => 'Label', 'name' => "Campos[$objeto][" . $campo["COLUMNS"]["Field"] . "][label]")); ?></td>
                        <td><?php echo $this->Form->input("", array('' => 'Tipo de input', 'options'=>array('texto'=>'Texto','email'=>'Email','numerico'=>'Numerico','fecha'=>'Fecha'),'name' => "Campos[$objeto][" . $campo["COLUMNS"]["Field"] . "][validacion]")); ?></td>
                        <td><?php echo $this->Form->hidden("", array('label' => 'TYPE', 'name' => "Campos[$objeto][" . $campo["COLUMNS"]["Field"] . "][Type]",'value' => $campo["COLUMNS"]["Type"])); ?>
                        <?php echo $this->Form->checkbox("", array('label' => 'Obligatorio', 'hiddenField' => false,  'name' => "Campos[$objeto][" . $campo["COLUMNS"]["Field"] . "][obligatorio]")); ?></td>
                    <?php else: ?>
                        <td><?php echo $this->Form->input("", array('label' => 'Label', 'name' => "Campos[$objeto][" . $campo["COLUMNS"]["Field"] . "][label]")); ?></td>
                    <?php endif; ?>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>

<?php endif; ?>
